home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / tsr.arc / MAPMEM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-05-22  |  21.6 KB  |  676 lines

  1. {**************************************************************************
  2. *   Maps system memory blocks for MS/PCDOS 2.0 and higher.                *
  3. *   Also maps expanded memory allocation blocks                           *
  4. *   Copyright (c) 1986 Kim Kokkonen, TurboPower Software.                 *
  5. *   Released to the public domain for personal, non-commercial use only.  *
  6. ***************************************************************************
  7. *   version 1.0 1/2/86                                                    *
  8. *   version 1.1 1/10/86                                                   *
  9. *     running under DOS 2.X, where block owner names are unknown          *
  10. *   version 1.2 1/22/86                                                   *
  11. *     a bug in parsing the owner name of the block                        *
  12. *     a quirk in the way that the DOS PRINT buffer installs itself        *
  13. *     minor cosmetic changes                                              *
  14. *   version 1.3 2/6/86                                                    *
  15. *     smarter filtering for processes that deallocate their environment   *
  16. *   version 1.4 2/23/86                                                   *
  17. *     add a map of Expanded memory (EMS) as well                          *
  18. *   version 1.5 2/26/86                                                   *
  19. *     change format of last memory block                                  *
  20. *     change to more reliable scheme of finding first block               *
  21. *       (thanks to Chris Dunford for pointing out a useful                *
  22. *        undocumented DOS function).                                      *
  23. *     support environment lengths up to 32K                               *
  24. *   version 1.6 3/8/86                                                    *
  25. *     support "verbose" output mode                                       *
  26. *       display open file handles                                         *
  27. *       show command line of each block                                   *
  28. *   version 1.7 3/24/86                                                   *
  29. *     work around Turbo 3.00B bug with Delete procedure and length 255    *
  30. *     filter out command lines of programs which relocate over their      *
  31. *       command line at PSP:$80.                                          *
  32. *     fix treatment of handle counts from PSP                             *
  33. *     add display of number of memory blocks per PSP to verbose mode      *
  34. *     accept V, -V, or /V for the verbose switch                          *
  35. *   version 1.8 4/20/86                                                   *
  36. *     change verbose mode to show each block individually                 *
  37. *   version 1.9 5/22/86                                                   *
  38. *     synchronize with RELEASE                                            *
  39. ***************************************************************************
  40. *   telephone: 408-378-3672, CompuServe: 72457,2131.                      *
  41. *   requires Turbo version 3 to compile.                                  *
  42. *   Compile with mAx dynamic memory = FFFF.                               *
  43. ***************************************************************************}
  44.  
  45. {$P128}
  46.  
  47. program MapMem;
  48.   {-look at the system memory map using DOS memory control blocks}
  49. const
  50.   Version = '1.9';
  51.   MaxBlocks = 100;            {max number of DOS memory blocks checked}
  52.   MaxVector = $FF;            {highest interrupt vector checked for trapping}
  53. type
  54.   Block =
  55.   record                      {store info about each memory block as it is found}
  56.     idbyte : Byte;
  57.     mcb : Integer;
  58.     psp : Integer;
  59.     len : Integer;
  60.     psplen : Integer;
  61.     env : Integer;
  62.     cnt : Integer;
  63.   end;
  64.   BlockType = 0..MaxBlocks;
  65.   BlockArray = array[BlockType] of Block;
  66.   registers =
  67.   record
  68.     case Integer of
  69.       1 : (ax, bx, cx, dx, bp, si, di, ds, es, flags : Integer);
  70.       2 : (al, ah, bl, bh, cl, ch, dl, dh : Byte);
  71.   end;
  72.   Pathname = string[64];
  73.  
  74. var
  75.   Blocks : BlockArray;
  76.   BlockNum : BlockType;
  77.   verbose : Boolean;
  78.   param : Pathname;
  79.  
  80.   function StUpcase(s : Pathname) : Pathname;
  81.     {-return the upper case of a string}
  82.   var
  83.     i : Byte;
  84.   begin
  85.     for i := 1 to Length(s) do s[i] := UpCase(s[i]);
  86.     StUpcase := s;
  87.   end {stupcase} ;
  88.  
  89.   procedure FindTheBlocks;
  90.     {-scan memory for the allocated memory blocks}
  91.   const
  92.     MidBlockID = $4D;         {byte DOS uses to identify part of MCB chain}
  93.     EndBlockID = $5A;         {byte DOS uses to identify last block of MCB chain}
  94.   var
  95.     mcbSeg : Integer;         {segment address of current MCB}
  96.     nextSeg : Integer;        {computed segment address for the next MCB}
  97.     gotFirst : Boolean;       {true after first MCB is found}
  98.     gotLast : Boolean;        {true after last MCB is found}
  99.     idbyte : Byte;            {byte that DOS uses to identify an MCB}
  100.  
  101.     function GetStartMCB : Integer;
  102.       {-return the first MCB segment}
  103.     var
  104.       reg : registers;
  105.     begin
  106.       reg.ah := $52;
  107.       MsDos(reg);
  108.       GetStartMCB := MemW[reg.es:(reg.bx-2)];
  109.     end {getstartmcb} ;
  110.  
  111.     procedure StoreTheBlock(var mcbSeg, nextSeg : Integer;
  112.                             var gotFirst, gotLast : Boolean);
  113.       {-store information regarding the memory block}
  114.     var
  115.       nextID : Byte;
  116.       pspAdd : Integer;       {segment address of the current PSP}
  117.       mcbLen : Integer;       {size of the current memory block in paragraphs}
  118.  
  119.     begin
  120.  
  121.       mcbLen := MemW[mcbSeg:3]; {size of the MCB in paragraphs}
  122.       nextSeg := Succ(mcbSeg+mcbLen); {where the next MCB should be}
  123.       pspAdd := MemW[mcbSeg:1]; {address of program segment prefix for MCB}
  124.       nextID := Mem[nextSeg:0];
  125.  
  126.       if gotLast or (nextID = EndBlockID) or (nextID = MidBlockID) then begin
  127.         BlockNum := Succ(BlockNum);
  128.         gotFirst := True;
  129.         with Blocks[BlockNum] do begin
  130.           idbyte := Mem[mcbSeg:0];
  131.           mcb := mcbSeg;
  132.           psp := pspAdd;
  133.           env := MemW[pspAdd:$2C];
  134.           len := mcbLen;
  135.           psplen := 0;
  136.           cnt := 1;
  137.         end;
  138.       end;
  139.  
  140.     end {storetheblock} ;
  141.  
  142.   begin
  143.  
  144.     {initialize}
  145.     mcbSeg := GetStartMCB;
  146.     gotFirst := False;
  147.     gotLast := False;
  148.     BlockNum := 0;
  149.  
  150.     {scan all memory until the last block is found}
  151.     repeat
  152.       idbyte := Mem[mcbSeg:0];
  153.       if idbyte = MidBlockID then begin
  154.         StoreTheBlock(mcbSeg, nextSeg, gotFirst, gotLast);
  155.         if gotFirst then mcbSeg := nextSeg else mcbSeg := Succ(mcbSeg);
  156.       end else if gotFirst and (idbyte = EndBlockID) then begin
  157.         gotLast := True;
  158.         StoreTheBlock(mcbSeg, nextSeg, gotFirst, gotLast);
  159.       end else begin
  160.         {start block was invalid}
  161.         WriteLn('corrupted allocation chain or program error');
  162.         Halt(1);
  163.       end;
  164.     until gotLast;
  165.  
  166.   end {findtheblocks} ;
  167.  
  168.   function Cardinal(i : Integer) : Real;
  169.     {-return an unsigned integer 0..65535}
  170.   begin
  171.     Cardinal := 256.0*Hi(i)+Lo(i);
  172.   end {cardinal} ;
  173.  
  174.   procedure StripNonAscii(var t : Pathname);
  175.     {-return an empty string if t contains any non-printable characters}
  176.   var
  177.     ipos : Byte;
  178.     goodname : Boolean;
  179.   begin
  180.     goodname := True;
  181.     for ipos := 1 to Length(t) do
  182.       if (t[ipos] <> #0) and ((t[ipos] < ' ') or (t[ipos] > '}')) then
  183.         goodname := False;
  184.     if not(goodname) then t := '';
  185.   end {stripnonascii} ;
  186.  
  187.   procedure ShowTheBlocks;
  188.     {-analyze and display the blocks found}
  189.   type
  190.     HexString = string[4];
  191.     Address = record
  192.                 offset, segment : Integer;
  193.               end;
  194.     VectorType = 0..MaxVector;
  195.   var
  196.     st, cline : Pathname;
  197.     b : BlockType;
  198.     StLen, DOSv : Byte;
  199.     CommandPSP : Integer;
  200.     Vectors : array[VectorType] of Address absolute 0 : 0;
  201.     Vtable : array[VectorType] of Real;
  202.     SumNum : BlockType;
  203.     Sum : BlockArray;
  204.  
  205.     function Hex(i : Integer) : HexString;
  206.       {-return hex representation of integer}
  207.     const
  208.       hc : array[0..15] of Char = '0123456789ABCDEF';
  209.     var
  210.       l, h : Byte;
  211.     begin
  212.       l := Lo(i); h := Hi(i);
  213.       Hex := hc[h shr 4]+hc[h and $F]+hc[l shr 4]+hc[l and $F];
  214.     end {hex} ;
  215.  
  216.     function DOSversion : Byte;
  217.       {-return the major version number of DOS}
  218.     var
  219.       reg : registers;
  220.     begin
  221.       reg.ah := $30;
  222.       MsDos(reg);
  223.       DOSversion := reg.al;
  224.     end {dosversion} ;
  225.  
  226.     function Owner(startadd : Integer) : Pathname;
  227.       {-return the name of the owner program of an MCB}
  228.     type
  229.       chararray = array[0..32767] of Char;
  230.     var
  231.       e : ^chararray;
  232.       i : Integer;
  233.       t : Pathname;
  234.  
  235.       function LongPos(m : Pathname; var s : chararray) : Integer;
  236.         {-return the position number of m in s, or 0 if not found}
  237.       var
  238.         mc : Char;
  239.         ss : Pathname;
  240.         i, maxindex : Integer;
  241.         found : Boolean;
  242.       begin
  243.         i := 0;
  244.         maxindex := SizeOf(s)-Length(m);
  245.         ss[0] := m[0];
  246.         if Length(m) > 0 then begin
  247.           mc := m[1];
  248.           repeat
  249.             while (s[i] <> mc) and (i <= maxindex) do
  250.               i := Succ(i);
  251.             if s[i] = mc then begin
  252.               Move(s[i], ss[1], Length(m));
  253.               found := (ss = m);
  254.               if not(found) then i := Succ(i);
  255.             end;
  256.           until found or (i > maxindex);
  257.           if not(found) then i := 0;
  258.         end;
  259.         LongPos := i;
  260.       end {longpos} ;
  261.  
  262.       procedure StripPathname(var pname : Pathname);
  263.         {-remove leading drive or path name from the input}
  264.       var
  265.         spos, cpos, rpos : Byte;
  266.       begin
  267.         spos := Pos('\', pname);
  268.         cpos := Pos(':', pname);
  269.         if spos+cpos = 0 then Exit;
  270.         if spos <> 0 then begin
  271.           {find the last slash in the pathname}
  272.           rpos := Length(pname);
  273.           while (rpos > 0) and (pname[rpos] <> '\') do rpos := Pred(rpos);
  274.         end else
  275.           rpos := cpos;
  276.         Delete(pname, 1, rpos);
  277.       end {strippathname} ;
  278.  
  279.       procedure StripExtension(var pname : Pathname);
  280.         {-remove the file extension}
  281.       var
  282.         dotpos : Byte;
  283.       begin
  284.         dotpos := Pos('.', pname);
  285.         if dotpos <> 0 then
  286.           Delete(pname, dotpos, 64); {<255 needed for Turbo version 3.00B bug}
  287.       end {stripextension} ;
  288.  
  289.     begin
  290.       {point to the environment string}
  291.       e := Ptr(startadd, 0);
  292.  
  293.       {find end of the standard environment}
  294.       i := LongPos(#0#0, e^);
  295.       if i = 0 then begin
  296.         {something's wrong, exit gracefully}
  297.         Owner := '';
  298.         Exit;
  299.       end;
  300.  
  301.       {end of environment found, get the program name that follows it}
  302.       t := '';
  303.       i := i+4;               {skip over #0#0#args}
  304.       repeat
  305.         t := t+e^[i];
  306.         i := Succ(i);
  307.       until (Length(t) > 64) or (e^[i] = #0);
  308.  
  309.       StripNonAscii(t);
  310.       if t = '' then
  311.         Owner := 'N/A'
  312.       else begin
  313.         StripPathname(t);
  314.         StripExtension(t);
  315.         if t = '' then t := 'N/A';
  316.         Owner := StUpcase(t);
  317.       end;
  318.  
  319.     end {owner} ;
  320.  
  321.     procedure InitVectorTable;
  322.       {-build real equivalent of vector addresses}
  323.     var
  324.       v : VectorType;
  325.  
  326.       function RealAdd(a : Address) : Real;
  327.         {-return the real equivalent of an address (pointer)}
  328.       begin
  329.         with a do
  330.           RealAdd := 16.0*Cardinal(segment)+Cardinal(offset);
  331.       end {realadd} ;
  332.  
  333.     begin
  334.       for v := 0 to MaxVector do
  335.         Vtable[v] := RealAdd(Vectors[v]);
  336.     end {initvectortable} ;
  337.  
  338.     procedure WriteHooks(start, stop : Integer);
  339.       {-show the trapped interrupt vectors}
  340.     var
  341.       v : VectorType;
  342.       sadd, eadd : Real;
  343.     begin
  344.       if start = stop then Exit;
  345.       sadd := 16.0*Cardinal(start);
  346.       eadd := 16.0*Cardinal(stop);
  347.       for v := 0 to MaxVector do begin
  348.         if (Vtable[v] >= sadd) and (Vtable[v] <= eadd) then
  349.           Write(Copy(Hex(v), 3, 2), ' ');
  350.       end;
  351.     end {writehooks} ;
  352.  
  353.     procedure SortByPSP(var Blocks : BlockArray; BlockNum : BlockType);
  354.       {-sort in order of ascending PSP}
  355.     var
  356.       i, j : BlockType;
  357.       temp : Block;
  358.     begin
  359.       for i := 1 to Pred(BlockNum) do
  360.         for j := BlockNum downto Succ(i) do
  361.           if Cardinal(Blocks[j].psp) < Cardinal(Blocks[Pred(j)].psp) then begin
  362.             temp := Blocks[j];
  363.             Blocks[j] := Blocks[Pred(j)];
  364.             Blocks[Pred(j)] := temp;
  365.           end;
  366.     end {SortByPSP} ;
  367.  
  368.     procedure SumTheBlocks(var Blocks : BlockArray;
  369.                            BlockNum : BlockType;
  370.                            var Sum : BlockArray;
  371.                            var SumNum : BlockType);
  372.       {-combine the blocks with equivalent PSPs}
  373.     var
  374.       prevPSP : Integer;
  375.       b : BlockType;
  376.     begin
  377.       SumNum := 0;
  378.       prevPSP := 0;
  379.       for b := 1 to BlockNum do begin
  380.         if Blocks[b].psp <> prevPSP then begin
  381.           SumNum := Succ(SumNum);
  382.           Sum[SumNum] := Blocks[b];
  383.           prevPSP := Blocks[b].psp;
  384.           if prevPSP = CSeg then
  385.             {don't include the environment as part of free block's length}
  386.             Sum[SumNum].len := 0;
  387.         end else
  388.           with Sum[SumNum] do begin
  389.             cnt := Succ(cnt);
  390.             len := len+Blocks[b].len;
  391.           end;
  392.         {get length of the block which owns the executable program}
  393.         {for checking vector trapping next}
  394.         if Succ(Blocks[b].mcb) = Blocks[b].psp then
  395.           Sum[SumNum].psplen := Blocks[b].len;
  396.       end;
  397.     end {sumblocks} ;
  398.  
  399.     procedure TransferTheBlocks(var Blocks : BlockArray;
  400.                                 BlockNum : BlockType;
  401.                                 var Sum : BlockArray;
  402.                                 var SumNum : BlockType);
  403.       {-fill in the Sum array with a little initialization}
  404.     var
  405.       b : BlockType;
  406.     begin
  407.       for b := 1 to BlockNum do begin
  408.         Sum[b] := Blocks[b];
  409.         with Sum[b] do begin
  410.           cnt := 1;
  411.           if (Succ(mcb) = psp) and (psp <> 0) then
  412.             psplen := len
  413.           else
  414.             psplen := 0;
  415.         end;
  416.       end;
  417.       SumNum := BlockNum;
  418.     end {transfertheblocks} ;
  419.  
  420.     function OpenHandles(psp : Integer) : Integer;
  421.       {-return the number of open handles owned by a process}
  422.     var
  423.       h, o : Integer;
  424.       b : Byte;
  425.     begin
  426.       h := 0;
  427.       if (psp <> 8) and (cline <> 'N/A') then
  428.         for o := 0 to 19 do begin
  429.           b := Mem[psp:$18+o];
  430.           if not(b in [$FF, 0..2]) then
  431.             h := Succ(h);
  432.         end;
  433.       OpenHandles := h;
  434.     end {openhandles} ;
  435.  
  436.     function CommandLine(psp : Integer) : Pathname;
  437.       {-return the command line of the PSP}
  438.     var
  439.       t, s : Pathname;
  440.       i : Byte;
  441.     begin
  442.       if (psp <> 8) then begin
  443.         Move(Mem[psp:$80], t, 65);
  444.         if t[0] > #64 then t[0] := #64;
  445.         s := t;
  446.         StripNonAscii(t);
  447.         if s <> t then
  448.           {command line has been written over}
  449.           t := 'N/A'
  450.         else
  451.           {strip leading blanks}
  452.           while (Length(t) > 0) and (t[1] = #32) do Delete(t, 1, 1);
  453.       end else
  454.         {psp=8 is a special block owned by DOS containing the CONFIG.SYS drivers}
  455.         t := '';
  456.       CommandLine := t;
  457.     end {commandline} ;
  458.  
  459.     function PrevBlock(b : BlockType; psp : Integer) : BlockType;
  460.       {-return highest block with number less than b having a PSP matching psp}
  461.       {-return 0 if none}
  462.     var
  463.       t : BlockType;
  464.       found : Boolean;
  465.     begin
  466.       found := False;
  467.       t := Pred(b);
  468.       while (t > 0) and not(found) do begin
  469.         found := (Sum[t].psp = psp);
  470.         if not(found) then t := Pred(t);
  471.       end;
  472.       PrevBlock := t;
  473.     end {prevblock} ;
  474.  
  475.   begin
  476.     WriteLn;
  477.     Write('Allocated Memory Map - by TurboPower Software - Version ', Version);
  478.  
  479.     if verbose then begin
  480.       WriteLn('  (verbose)');
  481.       WriteLn;
  482.       WriteLn(' PSP  MCB files bytes owner    command line  hooked vectors');
  483.       WriteLn('---- ---- ----- ----- -------- ------------- -----------------------------');
  484.     end else begin
  485.       WriteLn;
  486.       WriteLn;
  487.       WriteLn(' PSP  blks bytes owner    command line        hooked vectors');
  488.       WriteLn('----- ---- ----- -------- ------------------- ------------------------------');
  489.     end;
  490.  
  491.     DOSv := DOSversion;
  492.     CommandPSP := Blocks[2].psp;
  493.     InitVectorTable;
  494.     if verbose then
  495.       TransferTheBlocks(Blocks, BlockNum, Sum, SumNum)
  496.     else begin
  497.       SortByPSP(Blocks, BlockNum);
  498.       SumTheBlocks(Blocks, BlockNum, Sum, SumNum);
  499.     end;
  500.  
  501.     for b := 1 to SumNum do with Sum[b] do begin
  502.  
  503.       {get the command line which invoked the program}
  504.       if b = SumNum then
  505.         cline := ''
  506.       else
  507.         cline := CommandLine(psp);
  508.  
  509.       {write out numerical information}
  510.       Write(Hex(psp), ' ');   {PSP address}
  511.       if verbose then begin
  512.         Write(Hex(mcb), '  ', {MCB address}
  513.         OpenHandles(psp):2, '  '); {number of open file handles}
  514.       end else
  515.         Write(cnt:3, '  ');   {number of blocks}
  516.  
  517.       Write(16.0*Cardinal(len):6:0, ' '); {size of block in bytes}
  518.  
  519.       {get the program owning this block by scanning the environment}
  520.       if psp = CSeg then
  521.         st := 'free'
  522.       else if psp = CommandPSP then
  523.         st := 'command'
  524.       else if psp = Sum[1].psp then
  525.         st := 'config'
  526.       else if (DOSv >= 3) then begin
  527.         if verbose then begin
  528.           if Succ(mcb) = env then
  529.             {this is the environment block}
  530.             st := Owner(env)
  531.           else if PrevBlock(b, psp) <> 0 then
  532.             {this is the block that goes with the environment}
  533.             st := Owner(Sum[PrevBlock(b, psp)].env)
  534.           else
  535.             st := 'N/A';
  536.         end else if cnt > 1 then
  537.           st := Owner(env)
  538.         else
  539.           st := 'N/A';
  540.       end else
  541.         st := 'N/A';
  542.       while Length(st) < 9 do st := st+' ';
  543.       Write(st);
  544.  
  545.       {write the command line that invoked the program}
  546.       if verbose then
  547.         StLen := 13
  548.       else
  549.         StLen := 19;
  550.       if Length(cline) > StLen-3 then
  551.         cline := Copy(cline, 1, StLen-3)+'...'
  552.       else
  553.         while Length(cline) < StLen do cline := cline+' ';
  554.       Write(cline, ' ');
  555.  
  556.       {write the trapped interrupt vectors}
  557.       if verbose or (b <> SumNum) then
  558.         WriteHooks(psp, psp+psplen);
  559.  
  560.       WriteLn;
  561.     end;
  562.  
  563.   end {showtheblocks} ;
  564.  
  565.   procedure ShowTheEMSblocks;
  566.     {-map out expanded memory, if present}
  567.   const
  568.     EMSinterrupt = $67;       {the vector used by the expanded memory manager}
  569.     MaxHandles = 255;
  570.  
  571.   type
  572.     HandlePageRecord =
  573.     record
  574.       handle : Integer;
  575.       numpages : Integer;
  576.     end;
  577.  
  578.     PageArray = array[0..MaxHandles] of HandlePageRecord;
  579.     PageArrayPtr = ^PageArray;
  580.     Pathname = string[64];
  581.  
  582.   var
  583.     EMSregs : registers;
  584.     EMShandles : Integer;
  585.     Map : PageArrayPtr;
  586.     TotalPages : Integer;
  587.  
  588.     function EMSpresent : Boolean;
  589.       {-return true if EMS memory manager is present}
  590.     var
  591.       f : file;
  592.       present : Boolean;
  593.     begin
  594.       {"file handle" defined by the expanded memory manager at installation}
  595.       Assign(f, 'EMMXXXX0');
  596.       {$I-} Reset(f) {$I+} ;
  597.       present := (IOResult = 0);
  598.       if present then
  599.         Close(f);
  600.       EMSpresent := present;
  601.     end {EMSpresent} ;
  602.  
  603.     function EMSpagesAvailable(var TotalPages : Integer) : Integer;
  604.       {-return the number of 16K expanded memory pages available and unallocated}
  605.     begin
  606.       EMSregs.ah := $42;
  607.       Intr(EMSinterrupt, EMSregs);
  608.       if EMSregs.ah <> 0 then begin
  609.         WriteLn('EMS device not responding');
  610.         EMSpagesAvailable := 0;
  611.         Exit;
  612.       end;
  613.       EMSpagesAvailable := EMSregs.bx;
  614.       TotalPages := EMSregs.dx;
  615.     end {EMSpagesAvailable} ;
  616.  
  617.     function EMShandlesActive : Integer;
  618.       {-return the number of active EMS handles}
  619.     begin
  620.       EMSregs.ah := $4B;
  621.       Intr(EMSinterrupt, EMSregs);
  622.       if EMSregs.ah <> 0 then begin
  623.         WriteLn('EMS device not responding');
  624.         EMShandlesActive := 0;
  625.         Exit;
  626.       end;
  627.       EMShandlesActive := EMSregs.bx;
  628.     end {EMShandlesActive} ;
  629.  
  630.     procedure EMSpageMap(var PageMap : PageArray);
  631.       {-return an array of the allocated memory blocks}
  632.     begin
  633.       EMSregs.ah := $4D;
  634.       EMSregs.es := Seg(PageMap);
  635.       EMSregs.di := Ofs(PageMap);
  636.       EMSregs.bx := 0;
  637.       Intr(EMSinterrupt, EMSregs);
  638.       if EMSregs.ah <> 0 then
  639.         WriteLn('EMS device not responding');
  640.     end {EMSpageMap} ;
  641.  
  642.     procedure WriteEMSmap(PageMap : PageArray; handles : Integer);
  643.       {-write out the EMS page map}
  644.     var
  645.       h : Integer;
  646.     begin
  647.       WriteLn('block   bytes   (Expanded Memory)');
  648.       WriteLn('-----   ------');
  649.       for h := 0 to Pred(handles) do
  650.         WriteLn(h:5, '  ', (16384.0*Cardinal(PageMap[h].numpages)):7:0);
  651.     end {writeEMSmap} ;
  652.  
  653.   begin
  654.     if not(EMSpresent) then Exit;
  655.     EMShandles := EMShandlesActive;
  656.     WriteLn;
  657.     GetMem(Map, 4*EMShandles);
  658.     EMSpageMap(Map^);
  659.     WriteEMSmap(Map^, EMShandles);
  660.     WriteLn(' free  ', (16384.0*Cardinal(EMSpagesAvailable(TotalPages))):7:0);
  661.     WriteLn('total  ', (16384.0*Cardinal(TotalPages)):7:0);
  662.   end {showtheemsblocks} ;
  663.  
  664.  
  665. begin
  666.   verbose := False;
  667.   if ParamCount > 0 then begin
  668.     param := StUpcase(ParamStr(1));
  669.     if (param = 'V') or (param = '-V') or (param = '/V') then
  670.       verbose := True;
  671.   end;
  672.   FindTheBlocks;
  673.   ShowTheBlocks;
  674.   ShowTheEMSblocks;
  675. end.
  676.